Ext.define('mvcCouch.view.supplier.Contact' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.suppliercontact',
    requires: [
        'Ext.toolbar.TextItem'
    ],
    store: 'Contacts',
    title : '联系人列表',
    initComponent: function() {
        this.columns = [
            {header: '部门', dataIndex: 'department', flex: 1},
            {header: '职位', dataIndex: 'position',  flex: 1},
            {header: '姓名', dataIndex: 'name', flex: 1},
            {header: '性别', dataIndex: 'sex', flex: 1},
            {header: '电话', dataIndex: 'telephone', flex: 1},
            {header: '手机', dataIndex: 'mobile', flex: 1},
            {header: '传真', dataIndex: 'fax', flex: 1},
            {header: '邮箱', dataIndex: 'email', flex: 1}
        ];
        Ext.apply(this, {
            iconCls: 'icon-grid',
            frame: true,
            dockedItems: [{
                xtype: 'toolbar',
                items: [{
                    iconCls: 'icon-add',
                    text: '新增',
                    tooltip: '添加联系人',
                    scope: this,
                    handler: this.onAddClick
                }, {
                    iconCls: 'icon-delete',
                    text: '删除',
                    tooltip: '删除联系人',
                    disabled: true,
                    itemId: 'delete',
                    scope: this,
                    handler: this.onDeleteClick
                }]
            }]
        });
        this.height = 200;
		this.buttons = [
            {
                text: '保存联系人',
                iconCls: 'icon-save',
                action: 'savedoc',
                tooltip: '保存当前选中供应商的联系人'
            }
        ];
        this.callParent(arguments);
        this.getSelectionModel().on('selectionchange', this.onSelectChange, this);
    },
    onSelectChange: function(selModel, selections){
        this.down('#delete').setDisabled(selections.length === 0);
    },
    onDeleteClick: function(){
        supplierdelete = this.getView().getSelectionModel().getSelection()[0];
        if (supplierdelete) {
            this.store.remove(supplierdelete);
        }
    },
    onAddClick: function(){
        supplieradd = Ext.ModelMgr.create({
			        'department': "新建",
        }, 'mvcCouch.model.Contact');
        this.store.insert(0, supplieradd);
        suppliersinstance.add(supplieradd);
    }
});